package org.example.config;

import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.RedisSerializer;

import java.time.Duration;


public class RedisCacheConfig {

    @Bean
    public RedisCacheConfiguration cacheConfiguration() {
        RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig();
        //获取redis缓存对象序列化为json
        config = config.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer( RedisSerializer.json() ))
                        .entryTtl(Duration.ofDays(7))
                        .disableCachingNullValues();

        return config;
    }

}
